package com.fm.common;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;

public class ResultResponse<T> implements Serializable {
    private int status;
    private String msg;
    private T data;

    public int getStatus() {
        return status;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    @JsonIgnore
    //使之不在序列化结果当中
    public boolean isSuccessStatus() {
        return this.status == ResponseCode.SUCCESS.getCode();
    }

    private ResultResponse(int status) {
        this.status = status;
    }

    private ResultResponse(int status, T data) {
        this.status = status;
        this.data = data;
    }

    private ResultResponse(int status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    private ResultResponse(int status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public static <T> ResultResponse<T> isSuccess() {
        return new ResultResponse<T>(ResponseCode.SUCCESS.getCode());
    }

    public static <T> ResultResponse<T> isSuccessMessage(String msg) {
        return new ResultResponse<T>(ResponseCode.SUCCESS.getCode(), msg);
    }

    public static <T> ResultResponse<T> isSuccess(T data) {
        return new ResultResponse<T>(ResponseCode.SUCCESS.getCode(), data);
    }

    public static <T> ResultResponse<T> isSuccess(String msg, T data) {
        return new ResultResponse<T>(ResponseCode.SUCCESS.getCode(), msg, data);
    }

    public static <T> ResultResponse<T> isError() {
        return new ResultResponse<T>(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getDesc());
    }

    public static <T> ResultResponse<T> isErrorMessage(String errorMessage) {
        return new ResultResponse<T>(ResponseCode.ERROR.getCode(), errorMessage);
    }

    public static <T> ResultResponse<T> isErrorCodeMessage(int errorCode, String errorMessage) {
        return new ResultResponse<T>(errorCode, errorMessage);
    }
}
